package com.tanhua.server.controller;

import com.tanhua.server.service.TodayBestService;
import com.tanhua.server.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController
public class SoundController {

    @Autowired
    private TodayBestService todayBestService;


    /**
     * 桃花传音接收语音
     */

    @GetMapping("peachblossom")
    public ResponseEntity<VoiceVo> receiveVoice(){
        try {
            VoiceVo voiceVo = this.todayBestService.receiveVoice();
            return ResponseEntity.ok(voiceVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 桃花传音发送语音
     * @param soundFile
     * @return
     */
    @PostMapping("peachblossom")
    public ResponseEntity<Void> sendVoice(@RequestParam("soundFile") MultipartFile soundFile){
        try {
            this.todayBestService.sendVoice(soundFile);
            return ResponseEntity.ok(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }


}
